package com.scm.servlet.vender;

import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.scm.page.Page;
import com.scm.model.Vender;
import com.scm.service.VenderService;
@WebServlet("/main/pomain/queryvender")
public class QueryVenderServlet extends HttpServlet{
	private static final long serialVersionUID = -3040151794710775400L;
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		String currentpagestr = req.getParameter("currentpage");
		String vendercode = req.getParameter("vendercode");
		String name = req.getParameter("name");
		int currentpage = 1;
		if(currentpagestr != null && currentpagestr.matches("\\d++")) {
			currentpage = Integer.parseInt(currentpagestr);
		}
		Map<String,String> querymap = new HashMap<String,String>();
		querymap.put("vendercode", vendercode);
		querymap.put("name", name);
		try {
			
			Page<Vender> page = new VenderService().selectPage(currentpage, querymap);
			req.setAttribute("page", page);
			req.setAttribute("querymap", querymap);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		req.getRequestDispatcher("/gztm/vender.jsp").forward(req, resp);
	}
}
